// 邮箱验证
export function isMailbox (value) {
  const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(?:\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/
  return reg.test(value)
}

// 密码强度
export function passwordStrength (value) {
  if (value === '') return 
  //密码为八位及以上并且大小写字母数字特殊字符三项都包括 
  const strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
  //密码为八位及以上并且大小写字母、数字、特殊字符三项中有两项
  const mediumRegex = new RegExp("^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[a-z])(?=.*\\W))|((?=.*[0-9])(?=.*\\W))|((?=.*[A-Z])(?=.*\\W))).*$", "g");
  if(strongRegex.test(value)) {
    return '强'
  } else if (mediumRegex.test(value)){
    return '中'
  } else {
    return '弱'
  }
}

// 防抖函数
export function debounce (fn, delay) { 
  let timer = null 
  return (...args) => { 
    clearTimeout(timer)
    timer = setTimeout(() => { fn.apply(this, args) }, delay)
  }
}

// 手机验证
export function isPhone (value) {
  const reg = /^1[3-9]{1}[0-9]{9}$/
  return reg.test(value)
}